#ifndef GRID_H__
#define GRID_H__
#include <vector>
#include "C3DS_Loader.h"
using namespace std;

class Episode;

class GridSquare
{
private:
	bool passable;			// can players walk on it
	bool has_doodle;		// does the square have a model on it
	int x_index;			// used for selection
	int y_index;			// used for selection
	char name[30];			// the name of the square (such as "town" or something)
	float mesh_scale;		// the multiplier for glScalef for fitting objects on squares
	float height;			// the height of the doodle
	float rotation;			// the angle the object is going to be rotated in degrees;
	C3DModel doodle;		// a 3ds model to be drawn on the square
public:
	GridSquare(){passable=true;has_doodle=false; rotation=0;}// default constructor
	void setPassability(bool state) {passable=state;}		// set whether a player can walk on the square
	bool checkPassability() {return passable;}				// checks passability
	void setRotation(float rot){rotation=rot;}				// set rotation of the doodle
	bool hasDoodle() {return has_doodle;}					// checks to see if there is a doodle placed on this square
	bool placeDoodle(C3DModel model, float dimension=1);	// should check to see if there is a doodle
	void drawDoodle(void);									// draw a doodle if there is one assigned
	C3DModel getDoodle(void);								// returns the doodle on the square if there is one
	void clearDoodle(void) {has_doodle=false;}				// clear any doodle on the square 
	~GridSquare();											// delete the doodle if there is one
};

class Grid
{
private:
	unsigned x_squares;			// the number of squares width-wise
	unsigned y_squares;			// the number of squares height-wise
	float square_length;		// the length of a side of a square 
	GridSquare ** grid;			// a 2-dimensional array of the grid
	CVector3 position;			// the position of the bottom (closest) left corner;
	bool textured;				// whether or not a texture has been applied
	CTGALoader grid_texture;	// the texture for the entire grid

public:
	// MAKE: get size
	Grid() {};
	void initialize(unsigned x_sqrs, unsigned y_sqrs, float x_pos=0, float y_pos=0, float z_pos=0, float sqr_length=1);
	void drawGrid(void);	// draws the entire grid and everything on it
	bool setTexture(char * file);	// draws a texture over the entire grid;
	void setPassability(unsigned x, unsigned y, bool pass){grid[x][y].setPassability(pass);}
	void setRotation(unsigned x, unsigned y, float rot){grid[x][y].setRotation(rot);}
	bool checkPassability(unsigned x, unsigned y) {return grid[x][y].checkPassability();}
	//void addEpisode(int x, int y, Episode episode);
	//void callEpisode(int x, int y);
	void addDoodle(unsigned x, unsigned y, C3DModel model, float dimension=1);		// add a doodle to a specific grid square
	bool moveDoodle(unsigned x1, unsigned y1, unsigned x2, unsigned y2);	// mode a doodle from one square to another
	void calculatePaths(int x, int y, int distance);		// calculate the places a player can go
	~Grid();
};



#endif